## Title    : ￼NewBytes
## License  : MIT
## Author   : WingSummer
## Function : New the bin file with some zero bytes inited.
## Written on 2022/8/20

#coding=utf-8

def main():
    if service.version() < 5:
        service.toast("本插件版本脚本不支持！")
        return
    ok = BoolResult()
    # 2147483647 是 int 类型的最大值
    num = QtGui.QInputDialog.getInt(None,"新建填充","请输入预留字节数",0,0,2147483647,1,ok)
    if not bool(ok):
        service.toast("获取字节数失败！")
        return
    if not service.requestControl():
        service.toast("获取文档控制权限失败！")
        return
    controller.newFile()
    # 由于插件一旦获取控制文档权限，只要非空，文档无论咋么切换与插件无关，需要切换一下
    if not controller.switchDocument(reader.currentHostDoc(),False):
        service.toast("切换文档失败！")
        return
    controller.insert(0,Qt.QByteArray(num,0))
    controller.setKeepSize(True)
    service.toast("新建成功！") 

## ============= entry ============= ##

main()